﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyOA.Model;
using System.Data.SqlClient;
using System.Data;

namespace MyOA.DAL
{
    public class UserStateService
    {
        DBHelper db = new DBHelper();
        //根据UserStateId查找UserState信息
        public UserState getUserStateByUserStateId(int userStateId)
        {
            UserState userState = new UserState();
            using (SqlDataReader reader = db.getDataReader("proc_getUserStateByUserStateId", new SqlParameter("UserStateId", userStateId)))
            {
                if (reader.Read())
                {
                    userState.UserStateId = (int)reader["UserStateId"];
                    userState.UserStateName = (string)reader["UserStateName"];
                    
                }
                reader.Close();
                db.CloseConnection();
                return userState;
            }
        }
        //查找多有UserState信息
        public IList<UserState> GetAllUserState()
        {
            List<UserState> userStateList = new List<UserState>();
            using (DataTable table = db.getDataTable("proc_getAllUserState"))
            {
                foreach (DataRow row in table.Rows)
                {
                    UserState userState = new UserState();
                    userState.UserStateId = (int)row["UserStateId"];
                    userState.UserStateName = (string)row["UserStateName"];
                    userStateList.Add(userState);
                }
                return userStateList;
            }
        }

    }
}
